import Vue from 'vue'
import VueRouter from 'vue-router'
//引入Login组件
import Login from '../components/Login.vue'
import Home from '../components/Home.vue'
import Admin from '../components/Admin.vue'
import Welcome from '../components/Welcome.vue';
import Register from "../components/Register";

Vue.use(VueRouter)



  const routes = [
    {
      path:"/register",
      component: Register
    },
    {
      path:"/",
      redirect:"/login"
    },
    {
      path:"/login",
      component: Login
    },
    {
      path:"/home",
      component: Home,
      redirect:"/welcome",
      children:[
        {
          path:"/welcome",
          component: Welcome,
        },
        {
          path:"/home/task",
          name:'task',
          component: ()=>import('../components/user/List/taskList/Task.vue'),
        },
        {
          path:"/home/worker",
          name:'worker',
          component: ()=>import('../components/user/List/workerList/Worker.vue'),
        },
        {
          path:"/home/department",
          name:'department',
          component: ()=>import('../components/user/List/Department.vue'),
        },
        {
          path:"/home/profit",
          name:'profit',
          component: ()=>import('../components/user/List/profitList/Profit.vue'),
        },
        {
          path:"/home/salary",
          name:'salary',
          component: ()=>import('../components/user/userCenter/Salary.vue'),
        },
        {
          path:"/home/message",
          name:'message',
          component: ()=>import('../components/user/userCenter/Message.vue'),
        },
        {
          path:"/home/getAttendance",
          name:'getAttendance',
          component: ()=>import('../components/user/userCenter/GetAttendance.vue'),
        },
        {
          path:"/home/States",
          name:'states',
          component: ()=>import('../components/user/userCenter/holiday/States.vue'),
        },
        {
          path:"/home/Application",
          name:'application',
          component: ()=>import('../components/user/userCenter/holiday/Application.vue'),
        },
      ]
    },
    {
      path: "/admin",
      component: Admin,
      children:[
        {
          path:"/admin/adminWorker",
          name:'adminWorker',
          component: ()=>import('../components/admin/list/workerList/Worker'),
        },
        {
          path:"/admin/adminTask",
          name:'adminTask',
          component: ()=>import('../components/admin/list/taskList/Task'),
        },
        {
          path:"/admin/adminAttendance",
          name:'adminAttendance',
          component: ()=>import('../components/admin/list/attendanceList/Attendance'),
        },
        {
          path:"/admin/adminDepartment",
          name:'adminDepartment',
          component: ()=>import('../components/admin/list/departmentList/Department'),
        },
        {
          path:"/admin/adminHolidayAgree",
          name:'adminHolidayAgree',
          component: ()=>import('../components/admin/list/holidayList/HolidayAgree'),
        },
        {
          path:"/admin/adminProfit",
          name:'adminProfit',
          component: ()=>import('../components/admin/list/profitList/Profit'),
        },
        {
          path:"/admin/adminSalary",
          name:'adminSalary',
          component: ()=>import('../components/admin/list/Salary'),
        },
        {
          path:"/admin/adminCenter",
          name:'adminCenter',
          component: ()=>import('../components/admin/AdminCenter'),
        },
      ]
    }
    ]


const router = new VueRouter({
  routes
})
//导航监控器:
/*
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location,onResolve,onReject){
  if(onResolve || onReject) return originalPush.call(this,location,onResolve,onReject)
  return originalPush.call(this,location).catch(err => err)
}


router.beforeEach((to,from,next)=>{
  //to将要访问
  //from从哪访问
  //next接着干  重定向到url上next（）继续访问到tor路径
  if(to.path=='/login') return next();
  //获取user
  const userFlag= window.sessionStorage.getItem("user");//取出用户
  if(!userFlag) return  next('/login');
  next();//符合要求

})
*/

export default router
